package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Course;
import com.qk.management.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(path = "/courses")
public class CourseController {
    @Autowired
    private CourseService courseService;
    @GetMapping
    public Result list(Course  course){
       PageResult<Course> pageResult= courseService.list(course);
       return Result.success(pageResult);
    }

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        courseService.deleteById(id);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Course course){
        courseService.add(course);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result selectById(@PathVariable("id") Integer id){
       Course course= courseService.selectById(id);
       return Result.success(course);
    }

    @PutMapping
    public Result update(@RequestBody Course course){
        courseService.update(course);
        return Result.success();
    }

    @GetMapping("/list")
    public Result listAll(){
        List<Course> list= courseService.listAll();
        return Result.success(list);
    }
    @GetMapping("/subject/{subject}")
    public Result selectBySubject(@PathVariable("subject") Integer subject){
        List<Course> course=courseService.selectBySubject(subject);
        return Result.success(course);
    }

}
